package com.ruoyi.detection.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.detection.domain.RiceCanopyDetectionLog;
import com.ruoyi.detection.domain.RiceCanopyRet;
import com.ruoyi.detection.service.RiceCanopyService;
import com.ruoyi.framework.web.service.TokenService;
//import com.ruoyi.ys7Video.domain.VideoDao;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @program: class by cxf
 * @author: AbrahamBill
 * @date: 2022/6/30
 **/
@Api("水稻冠层检测模型")
@Slf4j
@RestController
@RequestMapping("/riceCanopyDetection")
public class RiceCanopyModelController extends BaseController {
    /**
     * 模型检测图像处理路径
     */
    @Value("${ruoyi.riceCanopyDetection}")
    private String riceDetectionUrl;

    /**
     * 存储文件的路径
     */
    @Value("${ruoyi.profile}")
    private String profile;

    @Autowired
    private TokenService tokenService;

    @Autowired
    private RiceCanopyService riceCanopyService;

    @ApiOperation("调用水稻病害模型检测")
    @PostMapping("/riceModel")
    public AjaxResult riceCanopyModel(@RequestParam("imageName") MultipartFile file,
                                      @RequestParam("device") String deviceSerial) throws IOException {
        if (!file.isEmpty()) {
            List<RiceCanopyDetectionLog> res_lst = riceCanopyService.insertRiceCanopyDetectionLog(file,deviceSerial);
            if(res_lst!=null){
                return AjaxResult.success(res_lst);
            }
            return AjaxResult.success("再试一次");
        }
        return AjaxResult.error("上传图片异常");
    }

    @ApiOperation("分页返回前端已经识别的水稻病害图数据")
    @PostMapping("/getImgs")
    public TableDataInfo getResultImgs(@RequestParam("deviceSerial") String serial){
        startPage();
        List<RiceCanopyRet> ret = riceCanopyService.selectRiceCanopyResultImg(serial);
        return getDataTable(ret);
    }

}
